<?php
declare (strict_types = 1);

namespace app\command;

use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;

class Plugin extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('plugin')
            ->addArgument('name', Argument::OPTIONAL, "name")
            ->addArgument('action', Argument::OPTIONAL, "store or del")
            ->setDescription('Say Hello');
    }

    protected function execute(Input $input, Output $output)
    {
        // 指令输出
        $name = $input->getArgument('name');
        if(!$name){
            $output->writeln('请输入名称');
        }else{
            $action = 'store';
            if ($input->getArgument('action')) {
                $action = $input->getArgument('action');
            }
            if($action == 'del'){
                $this->del($name);
            }elseif($action == 'store'){
                $this->store($name);
            }else{
                $output->writeln('请输入 store 或者 del');
            }
        }
    }

    protected function store($name)
    {
        $plugin_url = app()->getRootPath().'app/plugin';
        $plugin_temp = app()->getRootPath().'plugin';

        /*控制器*/
//        $controller = $plugin_temp . '/controller/Index.php';
////        copy($controller,'app/plugin/controller/'.ucfirst($name).'.php');
//
//        $content = fopen($controller,'r');
//        $str1 = $plugin_url . '/controller/';
//        if(!file_exists($str1)){
//            dir_mkdir($str1);
//        }
//        $new_file = $str1 . ucfirst($name) . '.php';
//        touch($new_file);
//        $w_content = fopen($new_file,'w');
//        dd($w_content);
//        while (!feof($content))
//        {
//            fwrite($w_content,fgets($content));
////            $str .= str_replace('Index',ucfirst($name),fgets($content));
//        }
        /*控制器end*/
    }
    protected function del($name)
    {

    }
}
